package ws.client;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.commons.io.IOUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

import sun.misc.BASE64Decoder;
public class Test {

	public static void main(String[] args) {
		
	}
	public void  yulan(OMElement element) throws IOException {
		
	/*	String test111 = element.toString();
		Element ele = Jsoup.parse(test111).body();
		Node node = ele.childNode(0).childNode(0).childNode(0).childNode(1).childNode(0);
		TextNode n1 = (TextNode) node;
		//拿到了要取的数据
		String result = n1.getWholeText();
		System.out.println("要取的数据："+result);
		
		if("true".equals("true")){
			return;
		}*/
		
				if (element != null) {
				String output = null;
				BASE64Decoder base = new BASE64Decoder();
				String test123 = element.toString();
				output = test123.substring(test123.indexOf("<cnisws:response>"), 
						test123.indexOf("</cnisws:response>")).replace("<cnisws:response>", "");
				byte[] byteOut = base.decodeBuffer(output);
						InputStream input = new ByteArrayInputStream(byteOut);
						BufferedInputStream in = new BufferedInputStream(input);
						String pdfFinalPath = "d:/pdf";
						if (!new File(pdfFinalPath).exists())
							new File(pdfFinalPath).mkdirs();
						pdfFinalPath += "/" + "GB_T%201.1-2009.pdf";
						if (!new File(pdfFinalPath).exists())
							new File(pdfFinalPath).mkdirs();
						pdfFinalPath += "/" + "".replace("","");
						if (new File(pdfFinalPath).exists()) {
							new File(pdfFinalPath).delete();
						}
						File file = new File(pdfFinalPath);
						file.createNewFile();
						OutputStream out = new FileOutputStream(pdfFinalPath);
						IOUtils.copy(in, out);
						IOUtils.closeQuietly(in);
						readPDF(file.getPath());
						//System.out.println(file.getPath());
		
	}
	}
	
	public static String readPDF(String pdfUrl) {
	    PDDocument helloDocument;
	    String t = "";
	    try {
	        helloDocument = PDDocument.load(new File(pdfUrl));
	        PDFTextStripper textStripper = new PDFTextStripper();
	        t = textStripper.getText(helloDocument);
	        helloDocument.close();
	     } catch (IOException e) {
	        // TODO Auto-generated catch block  
	        e.printStackTrace();
	     }
	        return t;
	 }
	
}
